package b3.widget.home.town
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.text.*;

	public class StatePane extends Sprite
	{
		//在初始化的时候  应该将整个状态栏记录为单独的一项 因为状态的栏目可能发生动态变化
		public function StatePane()
		{
			super();
			onRefresh();
				
			PlayerManager.getInstance().me.stateModel.addEventListener(ModelEvent.REFRESH, onRefresh);
		}
		
		/**
		 * 播放卡片效果
		 */ 
		public function playAddStateEffect(stateIndex:int):void
		{
			var stateConfig:StateConfig = Config.stateConfigs[stateIndex];
			var stateMovie:BasicWidget = new BasicWidget();
			var SunShine:Class = ResourceHelper.getInstance().getClassByName("SunShine");
			var sunShine:Sprite = new SunShine();
			sunShine.x = -50;
			sunShine.y = -50;
			stateMovie.addChild(sunShine);
			var StateIcon:Class = ResourceHelper.getInstance().getClassByName(stateConfig.iconImage[0]);
			var stateIcon:Sprite = new StateIcon();
			stateIcon.width = 150;
			stateIcon.scaleY = stateIcon.scaleX;
			stateIcon.x = 50;
			stateIcon.y = 50;
			stateMovie.addChild(stateIcon);
			stateMovie.x = BFont.stageWidth / 2 - 80;
			stateMovie.y = BFont.stageHeight / 2 - 100;
			WidgetManager.getInstance().popOut([stateMovie]);
			var targetPos:Point = this.localToGlobal(new Point(60, 0));
			var timeline:TimelineLite = new TimelineLite();
			timeline.append(new TweenLite(stateMovie, 2, {scaleX:1, scaleY:1}));
			timeline.append(new TweenLite(stateMovie, 1.5, {x: targetPos.x, y: targetPos.y, scaleX:0.1, scaleY:0.1, onComplete:stateMovie.close}));
		}
		
		/**
		 * 这里需要针对空间进行设计
		 */ 
		private function onRefresh(event:Event = null):void
		{
			//删除所有子节点
			for (var i:int = this.numChildren - 1; i >= 0; i--)
			{
				this.removeChildAt(0);
			} 
			var stateList:Array = PlayerManager.getInstance().me.stateModel.stateList;
			var pos:int = 0;
			for (i = 0; i < stateList.length; i++)
			{
				var stateInfo:StateInfo = stateList[i];
				if (stateInfo.state != StateConfig.SEAL && stateInfo.state != StateConfig.PROTECT)
				{
					var stateItem:StateItem = new StateItem(stateInfo);
					stateItem.x = pos;
					stateItem.y = 0;
					addChild(stateItem);
					pos += 25;
				}
			}
		}  
		
	}
}